from http.client import ImproperConnectionState
from re import sub
import subprocess
import os
import sys
os.system("g++ gen.cpp -o gen")
os.system("g++ std.cpp -o std")
os.system("g++ sol.cpp -o sol")
n = int(input())
lst = []
os.system("mkdir dat")
for i in  range(n):
    lst.append(subprocess.Popen(f"./gen > dat/{i}.tin && ./std < dat/{i}.tin > dat/{i}.tans && ./sol < dat/{i}.tin > dat/{i}.tout && echo finish run {i}",shell = True))

for p in lst:
    p.wait()

for i in range(n):
    with open(f"dat/{i}.tout") as f1:
        with open(f"dat/{i}.tans") as f2:
            if f1.read() != f2.read():
                print(f"wa on #{i}")
                os.system(f"cp dat/{i}.tin debug.in")
                os.system(f"cp dat/{i}.tans debug.ans")
                os.system(f"cp dat/{i}.tout debug.out")
